import { PagedRequestDto } from "@shared/component-base";
import { UploadFileDto } from "@shared/model/uploadfiledto";

export interface INewsDto {
  id: number;
  channelId: number;
  title: string;
  summer: string;
  keywords: string;
  author: string;
  content: string;
  readNum: number;
  createdTime: string;
 
}

export class NewsDto implements INewsDto {
  id: number;
  channelId: number;
  title: string;
  summer: string;
  keywords: string;
  author: string;
  content: string;
  readNum: number;
  createdTime: string;

  constructor(data?: INewsDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.id = data["id"];
      this.channelId = data["channelId"];
      this.title = data["title"];
      this.summer = data["summer"];
      this.keywords = data["keywords"];
      this.author = data["author"];
      this.content = data["content"];
      this.readNum = data["readNum"];
      this.createdTime = data["createdTime"];
     

    }
  }

  static fromJS(data: any): NewsDto {
    data = typeof data === 'object' ? data : {};
    let result = new NewsDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["id"] = this.id;
    data["channelId"] = this.channelId;
    data["title"] = this.title;
    data["summer"] = this.summer;
    data["keywords"] = this.keywords;
    data["author"] = this.author;
    data["content"] = this.content;
    data["readNum"] = this.readNum;
    data["createdTime"] = this.createdTime;
   

    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new NewsDto();
    result.init(json);
    return result;
  }
}

export class NewsListQueryDto extends PagedRequestDto {
  phone: string;
  keywords: string;

  init(data?: any) {
    if (data) {
      this.pageIndex = data["pageIndex"];
      this.pageSize = data["pageSize"];
      this.sortField = data["sortField"];
      this.sortOrder = data["sortOrder"];
      this.keywords = data["keywords"];
    }
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["pageIndex"] = this.pageIndex;
    data["pageSize"] = this.pageSize;
    data["sortField"] = this.sortField;
    data["sortOrder"] = this.sortOrder;
    data["keywords"] = this.keywords;
    return data;
  }
}

export interface INewsEditDto {
  id: number;
  channelId: string;
  title: string;
  summer: string;
  keywords: string;
  author: string;
  content: string;
  readNum: number;
  imageList: UploadFileDto[];
}

export class NewsEditDto implements INewsEditDto {
  id: number;
  channelId: string;
  title: string;
  summer: string;
  keywords: string;
  author: string;
  content: string;
  readNum: number;
  imageList: UploadFileDto[];

  constructor(data?: INewsEditDto) {
    if (data) {
      for (var property in data) {
        if (data.hasOwnProperty(property))
          (<any>this)[property] = (<any>data)[property];
      }
    }
  }

  init(data?: any) {
    if (data) {
      this.id = data["id"];
      this.channelId = data["channelId"]+'';
      this.title = data["title"];
      this.summer = data["summer"];
      this.keywords = data["keywords"];
      this.author = data["author"];
      this.content = data["content"];
      this.readNum = data["readNum"];
      this.imageList = data["imageList"];

    }
  }

  static fromJS(data: any): NewsEditDto {
    data = typeof data === 'object' ? data : {};
    let result = new NewsEditDto();
    result.init(data);
    return result;
  }

  toJSON(data?: any) {
    data = typeof data === 'object' ? data : {};
    data["id"] = this.id;
    data["channelId"] = this.channelId;
    data["title"] = this.title;
    data["summer"] = this.summer;
    data["keywords"] = this.keywords;
    data["author"] = this.author;
    data["content"] = this.content;
    data["readNum"] = this.readNum;
    data["imageList"] = this.imageList;

    return data;
  }

  clone() {
    const json = this.toJSON();
    let result = new NewsEditDto();
    result.init(json);
    return result;
  }
}


